package com.iweb.myfilter;

import org.apache.log4j.Logger;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;


/**
 * 自定义过滤器1
 * 拦截规则  所有请求都拦截
 */
@WebFilter(filterName = "Filter1",urlPatterns = {"/*"})
public class Filter1 implements Filter {
    private final static Logger logger = Logger.getLogger(Filter1.class);


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.debug("过滤器1初始化了");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        logger.debug("过滤器开始拦截");
        servletRequest.setCharacterEncoding("utf-8");
        filterChain.doFilter(servletRequest,servletResponse);
        //当有多个执行
        logger.debug("过滤器1执行之后。。。。");
    }

    @Override
    public void destroy() {
        logger.debug("过滤器销毁了");
    }
}